import mongoose from "mongoose";
import baseModel from "./base-model";
import md5 from "../util/md5";

export enum AdminRole {
  SuperAdmin = 0,
  Manager = 1,
  Approver = 2
}

export const adminSchema = new mongoose.Schema({
  ...baseModel,
  name: {
    type: String,
    required: false,
    default: "亲爱的管理员"
  },
  username: {
    type: String,
    required: true,
    unique: true
  },
  password: {
    type: String,
    required: true,
    set: (value: string) => md5(value),
    select: false
  },
  email: {
    type: String,
    required: true
  },
  role: {
    type: Number,
    required: false,
    default: AdminRole.Approver
  }
});
